package net.xdclasss.demo_project.controller;

import net.xdclasss.demo_project.domain.User;
import net.xdclasss.demo_project.service.UserService;
import net.xdclasss.demo_project.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/pub/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("login")
    public JsonData login(@RequestBody User user){

        System.out.println("user= "+user.toString());
        String token = userService.login(user.getUsername(), user.getPwd());
        if (token == null){
            return JsonData.buildError("用户名或者密码错误");
        }else {
            return JsonData.buildSuccess(token);
        }


    }
    @GetMapping("list")
    public JsonData userList(){
        List<User> list = userService.listUser();
        return JsonData.buildSuccess(list);
    }


}
